﻿

<html>
<head>

    <style>
        body {
            font-size: 10px;
        }

        td {
            font-size: 10px;
            width: 50px;
            padding-left: 10px;
            padding-right: 10px;
            border: dashed 1px;
        }

        .td_title {
            width: 100px;
        }

        .sp_t {
            float: right;
        }
    </style>

    <script src="https://code.jquery.com/jquery-1.11.3.js"></script>

    <script type="text/javascript">
        window.onload = function () {
            $(document).ready(function () {

                setInterval(function () {
                    $('#sc_info').remove();

                    var head = document.getElementsByTagName('head')[0];
                    var script = document.createElement('script');
                    script.id = "sc_info";
                    script.type = 'text/javascript';

                    $('#sc_info').attr("src", "");
                    $("#div_info").empty();
                    money = 0; money1 = 0;

                    var codeArray = [
                       ['sz000806', '2000', '17.22'],
                       ['sh601777', '2600', '11.38']
                    ];

                    var codes = [];
                    codeArray.forEach(function (e) { codes.push(e[0]); });
                    var codeStr = codes.join();

                    script.src = 'http://hq.sinajs.cn/list=' + codeStr;
                    head.appendChild(script);

                    codeArray.forEach(function (e) {
                        var elements = eval("hq_str_" + e[0]).split(",");
                        Info(elements, e[1], e[2]);
                    });

                    var msg = money.toFixed(0) + "/" + money1.toFixed(0);
                    document.title = msg;

                }, 500)

            });
        }


        function Info(elements, num, price) {
            var t = elements[3] - elements[2];
            var t1 = elements[3] - price;
            var str = "<table cellpadding='0' cellspacing='0'><tr><td class='td_title'>" + elements[0] + "<span class='sp_t'>(" + t.toFixed(2) + ")</span>"
                                                            + "</td><td>" + elements[3]
                                                            + "</td><td>" + elements[4]
                                                            + "</td><td>" + elements[5]
                                                            + "</td><td><span class='sp_t'>" + (t1 * num).toFixed(2) + "</span>"
                                                            + "</td></tr></table>";
            money += t * num;
            money1 += t1 * num;
            //console.debug(elements[3] + "-" + elements[2] + "-" + price + "*" + num);
            $("#div_info").append(str);

        }

    </script>

</head>

<body>
    <div id="div_info"></div>
</body>
</html>